#include <bits/stdc++.h>

using namespace std;

string a,b;
string rulea[10] , ruleb[10];
map <string,int> mp;
int main()
{
    cin>>a>>b;
    int n = 1;
    while(cin>>rulea[n]>>ruleb[n])n++;
    n--;
    queue <string> q;
    queue <int> step;
    q.push(a);
    step.push(0);
    while(!q.empty()){
        string temp = q.front();
        if(temp == b){cout<<step.front();return 0;}
        if(mp.count(temp)){
            q.pop();
            step.pop();
            continue;
        }
        mp[temp] = 1;
        for(int i=1 ; i<= n ; i++){
            int p = 0;
            while((p=temp.find(rulea[i],p))!=-1){
                q.push(temp.substr(0 , p)+ruleb[i]+temp.substr(p+rulea[i].length()));
                step.push(step.front()+1);
                p++;
            }
        }
        q.pop();
        step.pop();
    }
    cout<<"NO ANSWER!";
    return 0;
}
